package cn.zzzhy.entity;

import java.io.Serializable;

/**
 * @author zzzhy
 * @since 16/2/27 下午3:50
 */
public class URL implements Serializable,DeepCopy {

    //域名
    private final String host;
    //端口
    private final Integer port;
    //地址,不包含域名
    private final String location;
    //文件类型
    private final FileType fileType;

    public enum FileType {
        UNKNOWN,IMAGE,MV
    }

    public URL(String host, Integer port, String location) {
        this.host = host;
        this.port = port == null ? 80 : port;
        this.location = location;
        if(location.endsWith("jpg")||location.endsWith("png")||location.endsWith("jpeg")){
            this.fileType = FileType.IMAGE;
        }else if(location.endsWith("mp4")||location.endsWith("avi")
                ||location.endsWith("rmvb")||location.endsWith("mkv")){
            this.fileType = FileType.MV;
        }else{
            this.fileType = FileType.UNKNOWN;
        }
    }

    @Override
    public Object copy() {
        return this;
    }

    public String getHost() {
        return host;
    }

    public Integer getPort() {
        return port;
    }

    public String getLocation() {
        return location;
    }

    public FileType getFileType() {
        return fileType;
    }

    public boolean isHttps(){
        if (host.startsWith("https://")){
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return "URL{" +
                "host='" + host + '\'' +
                ", port=" + port +
                ", location='" + location + '\'' +
                ", fileType=" + fileType +
                '}';
    }
}
